using System;
using System.Diagnostics.Contracts;

namespace OpenLS.Spreadsheet
{
    partial class Worksheet
    {
        private class WorksheetValueChangedDisabler : IDisposable
        {
            private readonly Worksheet _worksheet;

            public WorksheetValueChangedDisabler(Worksheet worksheet)
            {
                Contract.Requires(worksheet != null);
                Contract.Requires(worksheet._cellvalueChangedDisabler == null);
                this._worksheet = worksheet;
                this._worksheet._cellvalueChangedDisabler = this;
            }

            public void Dispose()
            {
                this._worksheet._cellvalueChangedDisabler = null;
            }
        }
        private WorksheetValueChangedDisabler _cellvalueChangedDisabler;
        internal bool CellValueChangedDisabled { get { return _cellvalueChangedDisabler != null; } }
        internal IDisposable CreateCellValueChangedDisabler()
        {
            return new WorksheetValueChangedDisabler(this);
        }


        private class WorksheetCellAddedEventDisabler : IDisposable
        {
            private readonly Worksheet _worksheet;

            public WorksheetCellAddedEventDisabler(Worksheet worksheet)
            {
                Contract.Requires(worksheet != null);
                Contract.Requires(worksheet._worksheetCellAddedEventDisabler == null);
                this._worksheet = worksheet;
                this._worksheet._worksheetCellAddedEventDisabler = this;
            }

            public void Dispose()
            {
                this._worksheet._worksheetCellAddedEventDisabler = null;
            }
        }
        private WorksheetCellAddedEventDisabler _worksheetCellAddedEventDisabler;
        internal bool CellAddedEventDisabled { get { return _worksheetCellAddedEventDisabler != null; } }
        internal IDisposable CreateWorksheetCellAddedEventDisabler()
        {
            return new WorksheetCellAddedEventDisabler(this);
        }


        private class WorksheetCellPropertyEventDisabler : IDisposable
        {
            private readonly Worksheet _worksheet;

            public WorksheetCellPropertyEventDisabler(Worksheet worksheet)
            {
                Contract.Requires(worksheet != null);
                Contract.Requires(worksheet._worksheetCellPropertyEventDisabler == null);
                this._worksheet = worksheet;
                this._worksheet._worksheetCellPropertyEventDisabler = this;
            }

            public void Dispose()
            {
                this._worksheet._worksheetCellPropertyEventDisabler = null;
            }
        }
        private WorksheetCellPropertyEventDisabler _worksheetCellPropertyEventDisabler;
        internal bool CellPropertyEventDisabled { get { return _worksheetCellPropertyEventDisabler != null; } }
        internal IDisposable CreateWorksheetCellPropertyEventDisabler()
        {
            return new WorksheetCellPropertyEventDisabler(this);
        }
        
    }
}